List of Possible Cg Shader Inputs

In many cases, it is desirable to access information from the render state or from the 3-D transformation of the node that is currently being rendered. Instead of having to pass all this information manually, it is possible to name your variables in a special way that Panda3D will recognize and automatically populate with the relevant data.

The following table describes the inputs that can be used in Cg shaders.

CG Input Description
XXXREPLACE-ee61fca6b083d004cf79 431a92218195fb188d16XXX The model’s first texture. This requires that the model be textured in the normal manner. You may also use tex_1, tex_2, and so forth, if the model is multitextured.
XXXREPLACE-aad2030d32c6bd07680a 89692946efde09b91d11XXX If the model uses a 3D texture or a cubemap, use tex3D and texCUBE to access the color.
XXXREPLACE-21fbcf384fc17bb28018 65a21ed336b92493c1b4XXX Vertex Position. Vertex shader only. You may also use float4, in which case (w==1).
XXXREPLACE-3c26cfe76fa029981a75 06bb2bcac189877319d1XXX Vertex Normal. Vertex shader only.
XXXREPLACE-3d80c02aee56d6defe37 8bcdd5e24794f9326876XXX Vertex color. Vertex shader only.
XXXREPLACE-8b8da4cc28141f16d5e8 3abc3a68d68e95eb0e8eXXX UV(W) coordinate set associated with the model’s first texture. This requires that the model be textured in the normal manner. You may also use vtx_texcoord1, vtx_texcoord2, and so forth if the model is multitextured. Vertex shader only.
XXXREPLACE-5bc038169a0020623f8d cd0ae4556374650b04d4XXX From Panda3D 1.9 onward, this refers to the default (unnamed) set of UV(W) coordinates, if present, rather than being an alias for vtx_texcoord0. Vertex shader only.
XXXREPLACE-23ef7d4c817b2822c2e6 73c78c8b5eb483fcac99XXX From Panda3D 1.9 onward, this refers to a set of UV(W) coordinates with the given name. Vertex shader only.
XXXREPLACE-ad0140f2fd4a6d4e146b 8c74c7c750efa461aa63XXX Tangent vector associated with the model’s first texture. This can only be used if the model has been textured in the normal manner, and if binormals have been precomputed. You may also use vtx_tangent1, vtx_tangent2, and so forth if the model is multitextured. Vertex shader only.
XXXREPLACE-381351885d5d76fb7e18 750ab6d7412103daa265XXX Binormal vector associated with vtx_texcoord0. This can only be used if the model has been textured in the normal manner, and if binormals have been precomputed. You can also use vtx_binormal1, vtx_binormal2, and so forth if the model has been multitextured. Vertex shader only.
XXXREPLACE-7a5e56662cb421c54c76 0020cbeb31f1d436009eXXX Panda makes it possible to store arbitrary columns of user-defined data in the vertex table; see GeomVertexData. You can access this data using this syntax. For example, vtx_chicken will look for a column named “chicken” in the vertex array. Vertex shader only.
XXXREPLACE-c8fc7deb8dc4f7f7fd23 ddc1498d0b7379d391f7XXX A matrix that transforms from coordinate system X to coordinate system Y. See the section on Shaders and Coordinate Spaces for more information.
XXXREPLACE-e1cb5f95f7136699441c 100140dd9fb6374d3e7bXXX Transpose of trans_x_to_y
XXXREPLACE-74a608fcbc8719928d2e 18e1e2fa0b78cc2cc916XXX Row 0 of trans_x_to_y.
XXXREPLACE-4cc1e6e14061d4e1f3db 8fd0cb1853efde86b6a9XXX Row 1 of trans_x_to_y.
XXXREPLACE-e315d787cd670c569df9 e8d8f7685e87b0c5c0c5XXX Row 2 of trans_x_to_y.
XXXREPLACE-08d6bdd2cd3192ff29a1 dcf713578ae77af3e0bdXXX Row 3 of trans_x_to_y.
XXXREPLACE-ce3a4d3948710fa96ef0 58f1fbc06eef735bae59XXX Col 0 of trans_x_to_y.
XXXREPLACE-7f917d99225f9bc8c3e3 eae374aefbec7397d9e2XXX Col 1 of trans_x_to_y.
XXXREPLACE-e3425eb94ecede1cfa2c 413232fce3943b080f52XXX Col 2 of trans_x_to_y.
XXXREPLACE-77b91e4951525d1c803d eaeea40aac5b30199e11XXX Col 3 of trans_x_to_y.
XXXREPLACE-8e0d3d3d05f8a8ede3d9 8a314b80b433eb43f8edXXX Model-Space Transform of X, aka trans_x_to_model
XXXREPLACE-43f4ac889e8d13672c42 433675f935a24a54c363XXX Clip-Space Transform of X, aka trans_x_to_clip
XXXREPLACE-93a912eff5b3dd568eb3 c5dd0a4c691f3413d8b1XXX World-Space Transform of X, aka trans_x_to_world
XXXREPLACE-47d3e5da7ffbaae4c9c6 7060e619cd240ea290f8XXX View-Space Transform of X, aka trans_x_to_view
XXXREPLACE-fee247bf08084658898b 46da06728e00b21edd1aXXX Model-Space Position of X, aka row3_x_to_model
XXXREPLACE-958ba8168462233c8815 46aca915d8813c175813XXX Clip-Space Position of X, aka row3_x_to_clip
XXXREPLACE-f5d1d2ca0bd8496a1884 2063497eabe6e69261efXXX World-Space Position of X, aka row3_x_to_world
XXXREPLACE-3ba1704075cafa5e748c 11882509374659f414e5XXX View-Space Position of X, aka row3_x_to_view
XXXREPLACE-d222a852ebd7ca8b0802 3f72837efae5831804e1XXX Modelview matrix, transforming model-space coordinates to camera-space coordinates.
XXXREPLACE-60be7f6b418e47a9db0b 2c96c2aa8d0e7d10ffa7XXX Inverse of the model-view Matrix
XXXREPLACE-52adc2c0efe44900d2ca 017205a54aa97a5b9c4cXXX Transposed Modelview Matrix
XXXREPLACE-c866e1d716b46de92fa2 fb8e6ad1b78c1d332467XXX Inverse Transposed Modelview Matrix
XXXREPLACE-dd5317c543b932bbd863 f851e87a4f2847396041XXX Projection Matrix
XXXREPLACE-86f5992522b25d9340cf 434c1114c0c18ad6dffcXXX Inverse Projection Matrix
XXXREPLACE-a7f6281a5fe826c52acf cf03be06cecc4701888fXXX Transposed Projection Matrix
XXXREPLACE-29f98aaeacba44df301e da5297d9cd55cbf21263XXX Inverse Transposed Projection Matrix
XXXREPLACE-d8a2cb01739769c34e98 a35b100ef18edf35f80bXXX Composed Modelview/Projection Matrix
XXXREPLACE-a88574a14e3f8742c614 cacd4fbd5087b4db7a35XXX Inverse ModelProj Matrix
XXXREPLACE-71e529f58a7ad6ae1065 595d1623ba248b554145XXX Transposed ModelProj Matrix
XXXREPLACE-f996cfead6b49ac91872 8a79c7f7702f17d3f60aXXX Inverse Transposed ModelProj Matrix
XXXREPLACE-dcfaafa44c2e29ccba9f 412ef4529124b8790bfaXXX A constant vector that was stored using XXXREPLACE-166d220e69ac62fe398d901c39139782013 7430fXXX. Parameter anything would match data supplied by the call setShaderInput(“anything”, Vec4(x,y,z,w))
XXXREPLACE-33f7d4c784edc1032401 395e0ed3e3146e78676cXXX A constant texture that was stored using XXXREPLACE-166d220e69ac62fe398d901c39139782013 7430fXXX. Parameter anything would match data supplied by the call XXXREPLACE-f9c9794fb0d6f7fe5e7a2ea51202d9e8112 c12ffXXX
XXXREPLACE-588e0858060cd5bd0956 d8b5d2ac9f8eb2381dcbXXX A constant matrix that was stored using XXXREPLACE-166d220e69ac62fe398d901c39139782013 7430fXXX. Parameter anything would match data supplied by the call setShaderInput(“anything”, myNodePath). The matrix supplied is the nodepath’s local transform.
XXXREPLACE-257e17922805bff24aa8 762396511fa66a3f354bXXX X must be the name of a texture specified via shaderInput. Contains the U,V coordinates of the center of the texture. This will be (0.5,0.5) if the texture is not padded, but it will be less if the texture is padded.
XXXREPLACE-433b04446d1aec3445ad a3a39fbccb297bd4c83fXXX X must be the name of a texture specified via shaderInput. Contains the U,V offset of a single pixel in the texture (ie, the reciprocal of the texture size).
XXXREPLACE-69171425cea5d8acbc7d fac921ee96a219a2a485XXX The contents of the material attribute. Row 0 is ambient, Row 1 is diffuse, Row 2 is emission, Row 3 is specular, with shininess in W.
XXXREPLACE-5570aaf10355024eab81 92965c8d97f630a3bf2dXXX The contents of the color attribute. This is white unless the model has a flat color applied.
XXXREPLACE-ba42cb69ffe3f9060b85 7347bce66cb76dfb2bb4XXX

The contents of the color scale attribute. This is white unless the model has a color scale applied using nodePath.setColorScale.

This variable is only available in 1.6.2 and above.

XXXREPLACE-fb2bae8ffc7683a12e45 f48c0dbbd9dddd090412XXX

The fog parameters, where applicable. The values are in order: density, start, end, scale. The density is for exponential fog only, the start, end and scale are for linear fog only. The scale is equal to 1 / (end - start).

New in Panda3D 1.8.

XXXREPLACE-f8f82e6c43eb862a0e3a 4a4fc7a8d7ed3c3ba961XXX The fog color, if applicable. New in Panda3D 1.8.
XXXREPLACE-82dd291aeb81626a2e52 9f0da55c019b0acad15bXXX X must be an AmbientLight specified via a shaderInput. Contains the color of the light.
XXXREPLACE-69c9f94eee1f4a940098 7521a51d94bba8c55477XXX X must be an DirectionalLight specified via a shaderInput. Row 0 is color, row 1 is specular, row 2 is model-space direction, row 3 is model-space pseudo half-angle.
XXXREPLACE-aac20706a6aa8070ee01 04ead8781ec23c8090b1XXX

X must be an PlaneNode specified via a shaderInput. Contains the four terms of the plane equation.

This variable is only available in 1.6.2 and above.

XXXREPLACE-da5ef1742310c83ca6c2 0bf93354db2e601b3004XXX

Contains the parameters of the first clipplane (also: clipplane_1, clipplane_2, etc. for subsequent clip planes) in world-space coordinates.

This variable is only available in 1.6.2 and above.

XXXREPLACE-f74f6ab9ba89fb1b8390 f4a8ab3c7984f09a7749XXX Linearly interpolated Position, as supplied by the vertex shader to the fragment shader. Declare “out” in the vertex shader, “in” in the fragment shader.
XXXREPLACE-63d0cc1323d8f4e7878e 2753a99f542ab65905daXXX Linearly interpolated Primary color, as supplied by the vertex shader to the fragment shader. Declare “out” in the vertex shader, “in” in the fragment shader.
XXXREPLACE-827683dfa5c3fa699e40 f81c857e699a98def94aXXX Linearly interpolated Secondary color, as supplied by the vertex shader to the fragment shader. Declare “out” in the vertex shader, “in” in the fragment shader.
XXXREPLACE-8abf2bdc39d80c545af4 6db0b28b578f82cdb548XXX Linearly interpolated Texture Coordinate 0, as supplied by the vertex shader to the fragment shader. You may also use l_texcoord1, l_texcoord2, and so forth. Declare “out” in the vertex shader, “in” in the fragment shader.
XXXREPLACE-4e47b3a246d59a44dec4 afc627a05542120519a8XXX Output Color, as supplied by the fragment shader to the blending units. Fragment shader only. (COLOR0 is also accepted.)
XXXREPLACE-911e3c6c1252d4ee2efa 602d21d0a8dd1b9ccc63XXX Output auxiliary color. Only available if an auxiliary was obtained for the shaders target buffer/window. Fragment shader only.

Using Custom Shader Inputs

As of Panda3D 1.8.0, the capabilities for passing numeric shader inputs have been greatly enhanced. The available input types are as follows:

- Vec4
- Vec3
- Vec2
- Point4
- Point3
- Point2
- Mat4
- Mat3
- PTALMatrix4f
- PTALMatrix3f
- PTALVecBase4f
- PTALVecBase3f
- PTALVecBase2f
- PTAFloat
- PTADouble

(In Panda3D 1.9.0, the integer versions of these vectors and arrays are also supported.)

For definition let us consider the shader parameter float3. It’s type is float and format is Vec3 (meaning it can hold 3 elements) and a float3x3 input is of type float and format Mat3 (meaning it can hold 9 elements)

The main concept of the shader inputs is that the Cg input format and type is independent to the Panda3D input. The only condition is that the number of elements passed by the user through the setShaderInput() function of Panda3D and the number of elements expected by the shader input should be the same. For example a parameter uniform float4x4 mat[4] (total of 16*4 elements) could be set with(the below list is just a sample and there are more ways to represent it):

setShaderInput("input_name",PTALMat4f[4])
setShaderInput(PTALVecBase4f[16])
setShaderInput(PTAFloat[16*4])
setShaderInput(PTADouble[16*4])

But for some Cg input types there is no corresponding Panda3D type such as float3x2(Panda3D does not have a corresponding Mat3x2 class) Hence these input types can be initiated row-wise as

1 2 3

4 5 6

This row wise input can be sent to the Cg shader in any of the following ways(Note that the below list is just a sample and there are more ways to represent it)

setShaderInput(PTAFloat[6])
setShaderInput(PTADouble[6])
setShaderInput(PTALVecBase3f[2])
setShaderInput(PTALVecBase2f[3])

Now, the issue of common input types such as float, double, int, long. The GPU registers generally can handle only floats. Hence even if we do send a double it will be automatically type casted into float. Hence for such type of inputs we can use above types.

For example, input types such as

float3 var
bool3 var
half3 var
double3 var
fixed3 var
int3 var

Can be sent to your Cg shader program by (the below list is just a sample and there are more ways to represent it)

setShaderInput(PTAFloat[3])
setShaderInput(PTADouble[3])

Below is a sample code snippet that shows how you can use the new shader inputs.

from panda3d.core import Vec4
vec4 = Vec4(0.0,1.0,0.0,1.0)
myModel.setShaderInput("Inputs.vec4",vec4)

First import the necessary header to use the type of input. In our case it’s Vec4. The next statement shows a Vec4 input type. Then set the Vec4 as a shader input to your model.